CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -O2 -I./src/lib
LDFLAGS = 

# 源文件
CRYPTO_SOURCES = src/lib/sha256.c src/lib/aes.c src/lib/rsa.c src/lib/utils.c
CRYPTO_OBJECTS = $(CRYPTO_SOURCES:.c=.o)

# 目标文件
CRYPTO_LIB = libcrypto.a
DEMO_PROGRAM = crypto_demo

# 默认目标
all: $(CRYPTO_LIB) $(DEMO_PROGRAM)

# 编译静态库
$(CRYPTO_LIB): $(CRYPTO_OBJECTS)
	ar rcs $@ $^

# 编译演示程序
$(DEMO_PROGRAM): demos/crypto_demo.c $(CRYPTO_LIB)
	$(CC) $(CFLAGS) -o $@ $< $(CRYPTO_LIB) $(LDFLAGS)

# 编译规则
%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

# 清理
clean:
	rm -f $(CRYPTO_OBJECTS) $(CRYPTO_LIB) $(DEMO_PROGRAM)

# 安装
install: $(CRYPTO_LIB)
	install -d /usr/local/lib
	install -d /usr/local/include
	install -m 644 $(CRYPTO_LIB) /usr/local/lib/
	install -m 644 src/lib/crypto.h /usr/local/include/

# 卸载
uninstall:
	rm -f /usr/local/lib/$(CRYPTO_LIB)
	rm -f /usr/local/include/crypto.h

# 测试
test: $(DEMO_PROGRAM)
	./$(DEMO_PROGRAM)

# 帮助
help:
	@echo "可用的目标："
	@echo "  all        - 编译库和演示程序"
	@echo "  clean      - 清理编译文件"
	@echo "  install    - 安装库到系统"
	@echo "  uninstall  - 从系统卸载库"
	@echo "  test       - 运行演示程序"
	@echo "  help       - 显示此帮助信息"

.PHONY: all clean install uninstall test help 